package org.example.review.controller;

import com.common.result.Result;
import org.example.review.dto.DepartmentDTO;
import org.example.review.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.logging.Logger;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    private static final Logger logger = Logger.getLogger(DepartmentController.class.getName());

    @Autowired
    private DepartmentService departmentService;

    /**
     * 获取部门列表
     * @return 部门列表（树形结构）
     */
    @GetMapping("/list")
    public Result<List<DepartmentDTO>> getDepartments() {
        logger.info("接收到获取部门列表请求");
        try {
            List<DepartmentDTO> departmentList = departmentService.getDepartments();
            return Result.success(departmentList);
        } catch (Exception e) {
            logger.severe("获取部门列表失败: " + e.getMessage());
            return Result.error("获取部门列表失败: " + e.getMessage());
        }
    }
}
